Ubuntu 14.04
Sponsored Link

LXC : Install
2014/06/16
 
Install LXC which is an operating system-level virtualization.
[1] Install LXC
root@lxc:~#
apt-get -y install lxc
[2] Create and boot a Container.
# create a "ubuntu01" container with the template "ubuntu"

root@lxc:~#
lxc-create -n ubuntu01 -t ubuntu

Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ...
Installing packages in template: ssh,vim,language-pack-en
Downloading ubuntu trusty minimal ...
...
...
...
Current default time zone: 'Asia/Tokyo'
Local time is now:      Mon Jun 16 17:11:23 JST 2014.
Universal Time is now:  Mon Jun 16 08:11:23 UTC 2014.


##
# The default user is 'ubuntu' with password 'xxxxxx'!
# Use the 'sudo' command to run tasks as root in the container.
##

# show the list of Containers

root@lxc:~#
lxc-ls

ubuntu01
# start a Container as a daemon

root@lxc:~#
lxc-start -n ubuntu01 -d

# connect to the console of the Container

root@lxc:~#
lxc-console -n ubuntu01

Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself

Ubuntu 14.04 LTS ubuntu01 tty1

ubuntu01 login:
# just connected
# push "Ctrl+a" key and "q" key to exit the console of a Container

[3] There are some templates not only Ubuntu.
# there are some templates on there

root@lxc:~#
ls /usr/share/lxc/templates/

lxc-alpine     lxc-centos    lxc-fedora        lxc-oracle  lxc-ubuntu-cloud
lxc-altlinux   lxc-cirros    lxc-gentoo        lxc-plamo
lxc-archlinux  lxc-debian    lxc-openmandriva  lxc-sshd
lxc-busybox    lxc-download  lxc-opensuse      lxc-ubuntu

# for example, create a "CentOS" Container

root@lxc:~#
apt-get -y install yum

root@lxc:~#
lxc-create -n centos01 -t centos

root@lxc:~#
cat /var/lib/lxc/centos/tmp_root_pass
 
# make sure root password

xxxxxxxxxxxxxxxxx
# start the Container

root@lxc:~#
lxc-start -n centos01 -d

# connect to the console of Container

root@lxc:~#
lxc-console -n centos01

Connected to tty 1
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself

CentOS release 6.5 (Final)
Kernel 3.13.0-29-generic on an x86_64

centos01 login:
[4] Other basic usages.
# execute an application with booting a Container

root@lxc:~#
lxc-start -n ubuntu01 /bin/echo "Welcome to the LXC World!"

Welcome to the LXC World!
# stop a Container as a daemon

root@lxc:~#
lxc-stop -n ubuntu01
# delete a Container

root@lxc:~#
lxc-destroy -n ubuntu01
# show info of a Container

root@lxc:~#
lxc-info -n ubuntu01
Name:           ubuntu01
State:          STOPPED

# clone a Container from an existing Container

root@lxc:~#
lxc-clone ubuntu01 ubuntu02

Created container ubuntu02 as copy of ubuntu01
# take a snapshot of a Container

root@lxc:~#
lxc-snapshot -n ubuntu01

lxc_container: Snapshot of directory-backed container requested.
lxc_container: Making a copy-clone. If you do want snapshots, then
lxc_container: please create an aufs or overlayfs clone first, snapshot that
lxc_container: and keep the original container pristine.
root@lxc:~#
lxc-snapshot -n ubuntu01 --list
 
# make sure

snap0 (/var/lib/lxcsnaps/ubuntu01) 2014:06:16 21:36:50
# restore from a snapshot

root@lxc:~#
lxc-snapshot -n ubuntu01 -r snap0
# connect to a Container which is running as a daemon

root@lxc:~#
lxc-info -n ubuntu01 | grep IP

IP:             10.0.1.5
root@lxc:~#
ssh ubuntu@10.0.1.5

ubuntu@10.0.1.5's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-29-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Tue Jun 16 20:20:56 2014
ubuntu@ubuntu01:~$
[5] It's possible to access to services with HTTP or SSH and others which is running in Containers as a daemon.
# default networking settings

root@lxc:~#
egrep -v "^#|^$" /etc/default/lxc-net

USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.0.1.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.1.0/24"
LXC_DHCP_RANGE="10.0.1.2,10.0.1.254"
LXC_DHCP_MAX="253"

# bridge networking is configured like follows by default settings

root@dlp:~#
ifconfig | grep -A1 lxcbr0

lxcbr0    Link encap:Ethernet  HWaddr 00:00:00:00:00:00
          inet addr:10.0.1.1  Bcast:10.0.1.255  Mask:255.255.255.0

# make sure the IP address of a Container which is running as a daemon

# it's possible to access to the IP address of a Container with HTTP or SSH

root@dlp:~#
lxc-info -n ubuntu01 | grep IP

IP:             10.0.1.77
 
Tweet